'''
Created on Jan 29, 2010

@author: madsk
'''

from PyQt4 import QtGui, QtCore

class SliderDialog(QtGui.QDialog):
    def __init__(self, label, parent=None):
        super(SliderDialog, self).__init__(parent)
        
        self._vbox = QtGui.QVBoxLayout(self)
        self.setLayout(self._vbox)

        self._vbox.addWidget(QtGui.QLabel(label))
        
        self._slider = QtGui.QSlider(QtCore.Qt.Horizontal)
        self._slider.setRange(0, 200)
        self._slider.setValue(100)
        self._slider.setTickInterval(25)
        self._vbox.addWidget(self._slider)
        
        self._buttonbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|
                                                 QtGui.QDialogButtonBox.Cancel)
        self._vbox.addWidget(self._buttonbox)
        
        self._buttonbox.clicked.connect(self._handleButtonClicked)
        
    def _handleButtonClicked(self, button):
        if self._buttonbox.standardButton(button) == QtGui.QDialogButtonBox.Ok:
            self.done(1)
        else:
            self.done(0)
            
    def getSliderValue(self):
        return float(self._slider.value()) / 100
